Skip to main content

Getting Suppliers From Postcode Proximity

Introduction

Here, we will understand the flow of getting the suppliers from the postcode proximity.

Flow Diagram

Flow of code

  1. Upon receiving the user's input of postcode, service type, supplier type and franchises, an API call is made to the getSuppliersFromPostcodeProximity endpoint.
  2. The first step entails identifying all suppliers located in the proximity of the given postcode within the Algolia.
  3. In order to accomplish this, we retrieve the precise latitude and longitude coordinates corresponding to the provided postcode.
  4. To optimize the process, we initially verify if the postcode exists within our internal database. If found, we directly retrieve the associated latitude and longitude from the database.
  5. In cases where the postcode is not present in our database, we execute an API call to postcode.io to obtain the necessary latitude and longitude data.
  6. If the "postcode.io" API fails to locate the specified location, we leverage the Google Maps API to acquire the latitude and longitude information.
  7. If we fail to get the data through Google Maps, we resort to approximating the latitude and longitude by making minor adjustments to the provided postcode.
  8. With the latitude and longitude successfully obtained, a call is made to Algolia, retrieving all suppliers within the vicinity of the specified postcode.
  9. Within the Algolia call, we effectively apply the supplier type filter while also ensuring that the supplier is capable of providing services within the given distance.
  10. Subsequently, we proceed to filter out any service units that have not been approved by the lease company.
  11. Further, we eliminate any service units that do not offer the specific service types requested by the customer.
  12. Next step is to append franchise details to the service units.
  13. Final filter is to eliminate any service units that do not offer the specific franchises requested by the customer.
  14. Finally, the resulting list of service units meeting all the specified criteria is promptly returned to the client.

Configurable values

  1. Supplier Proximity: Can be set from by the admin for each lease company.
  2. Number of service units to be fetched from algolia per call: Can be set while making the algolia call (hitsPerPage).

Inputs by the client

  1. Postcode
  2. Service Type
  3. Supplier Type
  4. Franchises (Only if supplier type is franchise)

External APIs used

  1. https://api.postcodes.io/postcodes/${postcode}

Relation between user input and filtering of suppliers

  1. If the customer selects supplier type as Franchise, then only the Franchise suppliers will be returned.
  2. If the customer selects supplier type as Independent, then only the Independent suppliers will be returned.
  3. If the customer selects supplier type as Mobile, then any Independent or Franchise type garage who also offer Mobile services will be returned.
  4. If the customer chooses 2 service types then only the suppliers who have both the service types will be returned. (This applies only in the case of weblink enquiries, since book-in enquiry only allows one service type at a time).
Status: Accepted
Category: Protected
Authored By: Shubham H on Aug 10, 2023